(function (vc, vm) {
    vc.extends({
        data: {
            editProductCategoryInfo: {
                categoryId: '',
                categoryName: '',
                seq: '',
                cateTypes: [],
                cateType: '',
                isShows: [],
                isShow: '',
                parentCategoryId: '',
                categoryLevel: ''
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('editProductCategory', 'openEditProductCategoryModal', function (_params) {
                $that.refreshEditProductCategoryInfo();
                vc.getDict('product_category', "is_show", function (_data) {
                    $that.editProductCategoryInfo.isShows = _data;
                });
                vc.getDict('product_category', "cate_type", function (_data) {
                    $that.editProductCategoryInfo.cateTypes = _data;
                });
                $('#editProductCategoryModel').modal('show');
                vc.copyObject(_params, $that.editProductCategoryInfo);
            });
        },
        methods: {
            editProductCategoryValidate: function () {
                return vc.validate.validate({
                    editProductCategoryInfo: $that.editProductCategoryInfo
                }, {
                    'editProductCategoryInfo.categoryName': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "分类名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "100",
                            errInfo: "分类名称不能超过100位"
                        },
                    ],
                    'editProductCategoryInfo.seq': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "显示序号不能为空"
                        },
                        {
                            limit: "num",
                            param: "",
                            errInfo: "显示序号不是有效数字"
                        },
                    ],
                    'editProductCategoryInfo.isShow': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "是否显示不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "2",
                            errInfo: "是否显示格式错误"
                        },
                    ],
                    'editProductCategoryInfo.cateType': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "分组目录不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "2",
                            errInfo: "分组目录格式错误"
                        },
                    ],
                    'editProductCategoryInfo.categoryId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "分类ID不能为空"
                        }
                    ]
                });
            },
            editProductCategory: function () {
                if (!$that.editProductCategoryValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                $that.editProductCategoryInfo.shopId = vc.getCurrentCommunity().shopId;
                vc.http.apiPost(
                    '/productCategory.updateProductCategory',
                    JSON.stringify($that.editProductCategoryInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#editProductCategoryModel').modal('hide');
                            vc.emit('productCategoryManage', 'listProductCategory', {});
                            vc.toast("修改成功");
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            refreshEditProductCategoryInfo: function () {
                $that.editProductCategoryInfo = {
                    categoryId: '',
                    categoryName: '',
                    cateTypes: [],
                    cateType: '',
                    seq: '',
                    isShows: [],
                    isShow: '',
                    parentCategoryId: '',
                    categoryLevel: ''
                }
            }
        }
    });
})(window.vc, window.$that);
